const express = require('express')
const app = express()

// vue
const Vue = require('vue');
const main = new Vue({
    template: '<div>Hello World</div>'
});

//ssr
const renderer = require('vue-server-renderer').createRenderer({
    template: require('fs').readFileSync('./index.template.html', 'utf-8')
});

const context = {
    title: 'vue ssr',
    meta: `
        <meta name="keywords" content="vue ssr" />
        <meta name="author" content="billy" />
    `
};

app.get('/', (req, res) => {
    renderer.renderToString(main, context, (err, html) => {
        if (err) throw err
        res.send(html)
    });
})

app.listen(3000, () => console.log('Example app listening on port 3000!'))